package com.yami.shop.bean;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.yami.shop.bean.bo.SmsInfoBo;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Yami
 */
public class SmsInfoContext {

    /** The request holder. */
    private static ThreadLocal<List<SmsInfoBo>> smsInfoHolder = new ThreadLocal<List<SmsInfoBo>>();


    public static List<SmsInfoBo> get(){

        List<SmsInfoBo> list = smsInfoHolder.get();
        if (CollectionUtil.isEmpty(list)) {
            return new ArrayList<>();
        }
        return smsInfoHolder.get();
    }

    public static void set(List<SmsInfoBo> smsInfoBos){
         smsInfoHolder.set(smsInfoBos);
    }

    public static void put(SmsInfoBo smsInfoBo){
        List<SmsInfoBo> smsInfoBos = smsInfoHolder.get();
        if (CollectionUtil.isEmpty(smsInfoBos)) {
            smsInfoBos = new ArrayList<>();
        }
        smsInfoBos.add(smsInfoBo);
        smsInfoHolder.set(smsInfoBos);
    }

    public static void clean() {
        if (smsInfoHolder.get() != null) {
            smsInfoHolder.remove();
        }
    }
}
class t{
    public static void main(String[] args) {
        {
            d a=new d();
            a.setData("群组中各种通知的操作数据");
            a.setExtra("");
            a.setOperatorUserId("2");
            a.setData("aaa");
            a.setMessage("邀请人进群了");
            String s = JSON.toJSONString(a);
            System.out.println(s);
        }
    }
}

@Data
class d{
    private  String operatorUserId;
    private String data;
    private String operation;
    private String message;
    private String extra;
}
